import {Component, OnInit} from '@angular/core';
import {AlertService} from "./services/alert.service";
import {AuthService} from "./services/auth.service";
import {HostService} from "./services/host.service";
import {AdminModule} from "./pages/admin/admin.module";
import {AdminService} from "./services/admin.service";
import {MenuVo} from "./vo/MenuVo";
import {EventbusService} from "./services/eventbus.service";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent  implements OnInit{
  isCollapsed = false;
  ticket: string
  menulist: Array<MenuVo>;
  subscription: any;
  isloginstate = false;


  constructor(private alertService: AlertService,
              private authService: AuthService,
              private hostService: HostService,
              private eventbus: EventbusService,
              private adminService: AdminService) {
    this.menulist = new Array();
  }

  ngOnInit(): void {
    this.loadMenu()
    this.subscription = this.eventbus.on('LOGIN_SUCCESS')
      .subscribe(() => {
      this.loadMenu()
        // this.changeTologgedState();
      })
    this.subscription = this.eventbus.on('LOG_OUT')
      .subscribe(() => {
        // this.changeTOLoginOUtState();
        this.menulist = new Array();
        this.isloginstate = false;

      })
  }

  loadMenu() {
    this.menulist = new Array<MenuVo>();
    this.authService.getMenuList()
      .then((data: any) => {
        if (data.msg == 'ok') {
          this.menulist = data.list;
          var menuVo = new MenuVo();

          var menuVo1 = new MenuVo();
          menuVo.name="关闭"
          menuVo1.name="退出"
          menuVo1.path="/p401"

          menuVo.child.push(menuVo1)
          this.menulist.push(menuVo)
        }
      })
  }


}
